package cn.itcast.Proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author : 叶荻风
 * @create : 2024/8/7 10:37
 */
public class LogMethodInterceptor implements MethodInterceptor {
    private Object target;

    public LogMethodInterceptor(Object target) {
        this.target = target;
    }

    public LogMethodInterceptor() {
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //Object o 增强过的对象 Method原方法，objects 入参，methodProxy 增强过的方法
        System.out.println("before method call: "+method.getName());
        Object o1 = method.invoke(target, objects);
        System.out.println("after method call: "+method.getName());
        return o1;
    }
}
